/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.wholeconsulting.pacc.persistance.database;

import ar.com.wholeconsulting.pacc.model.Acero;
import ar.com.wholeconsulting.pacc.persistance.JPASession;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author pable
 */
public class AceroImporter extends Importer {

    private static final String QUERY = "select * from astm;";

    public AceroImporter(Connection con) {
        super(con);

    }

    @Override
    protected void importData(ResultSet rs) {
        try {
            Acero acero = new Acero();
            acero.setNombre(rs.getString(1));
            Double[] xs = {150.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 650.0, 700.0, 750.0, 800.0, 850.0, 900.0};
            List<Double> lis = Arrays.asList(xs);
            acero.getxValues().addAll(lis);
            for (int i = 2; i < 16; i++) {
                acero.getyValues().add(rs.getDouble(i));
            }
            JPASession.getInstance().getManager().persist(acero);
        } catch (SQLException ex) {
            Logger.getLogger(AceroImporter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void importaData() {
        try {
            super.queryData(QUERY);
        } catch (SQLException ex) {
            Logger.getLogger(AceroImporter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
